package com.itheima.reggie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.reggie.entity.User;
import com.itheima.reggie.mapper.UserMapper;
import com.itheima.reggie.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Service
public class UserServiceImpl implements UserService {
    @Autowired(required = false)
    private UserMapper userMapper;

    /**
     * 根据phone 查询有没有这个用户
     * @param phone
     * @return
     */
    @Override
    public User findUserByPhone(String phone) {
        LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<>();
        lqw.eq(User::getPhone,phone);
        return userMapper.selectOne(lqw);
    }

    /**
     * 添加用户
     * @param user
     * @return
     */
    public int insert(User user){
        int rows = userMapper.insert(user);
        return rows;
    }

    @Override
    public User findById(Long id) {
        User user = userMapper.selectById(id);
        return user;
    }
}
